﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-12-13 12:49:25
// 负责人：lvsc
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
using System.Configuration;

namespace OF.Component.DAL
{

    /// <summary>
    ///模板城市关联 数据访问层
    /// </summary>	
    internal partial class ExpressFeeTplCity
    {

        /// <summary>
        /// 根据断言条件获取单个模板城市关联
        /// </summary>
        public ExpressFeeTplCityInfo QuerySingle(Expression<Func<ExpressFeeTplCityInfo, bool>> predicate)
        {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }

        /// <summary>
        /// 根据断言条件获获取模板城市关联列表
        /// </summary>
        public IList<ExpressFeeTplCityInfo> QueryList(Expression<Func<ExpressFeeTplCityInfo, bool>> predicate)
        {
            return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
        }
        /// <summary>
        /// 批量插入
        /// </summary>
        public void BatchInsert(IList<ExpressFeeTplCityInfo> list)
        {
            var connStr = ConfigurationManager.ConnectionStrings[ConnectionStringKey].ConnectionString;
            var conn = new SqlConnection(connStr);
            var tableName = "ExpressFeeTplCity";
            SqlConnectionExtension.BulkInsert<ExpressFeeTplCityInfo>(conn, tableName, list);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids">id集合，逗号间隔</param>
        public void BatchDelete(string inStr)
        {
            string szSql = string.Format("Delete from ExpressFeeTplCity where ExpressFeeTplCity in( {0})", inStr);
            Database db = DatabaseFactory.CreateDatabase(ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(szSql);
            if (!string.IsNullOrWhiteSpace(inStr))
            {
                try
                {
                    db.ExecuteNonQuery(dbc);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        /// <summary>
        /// 根据模版Id逻辑删除模版下的所有城市
        /// </summary>
        /// <param name="expressFeeTplId">模版ID</param>
        public void LogicDeleteByTplId(int expressFeeTplId) {
            string szSql = string.Format("Update  ExpressFeeTplCity set IsActive= 0 where ExpressFeeTplID ={0}", expressFeeTplId);
            Database db = DatabaseFactory.CreateDatabase(ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(szSql);
            if (expressFeeTplId>0)
            {
                try
                {
                    db.ExecuteNonQuery(dbc);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }


    }

}